(function(w) {
	/**
	 * websql 数据库操作
	 * 2017.06.19 gehaiqing
	 */
	var dao = {
		/**
		 * 打开/创建数据库
		 * IOS最大只能创建50M，超过会报错	20170630
		 */
		openDB: function() {
			this.db = openDatabase('hf_house_check', '1.0', '恒富验房', 50 * 1024 * 1024); //50M
		},
		/**
		 * 创建表结构
		 */
		createTabels: function() {
			this.db.transaction(function(tx) {
				//用户表
				tx.executeSql(
					"create table if not exists hf_yf_user (id UNIQUE, name , downloaded)", [],
					function(tx, result) {
						console.log('创建用户表成功');
					},
					function(tx, error) {
						alert('创建用户表失败:' + error.message);
					});

				//验房任务批次表
				tx.executeSql(
					"create table if not exists hf_yf_batch (id UNIQUE, user_id , name , downloaded ,download_time , is_updated,building_name )", [],
					function(tx, result) {
						console.log('创建验房任务表成功');
					},
					function(tx, error) {
						alert('创建验房任务表失败:' + error.message);
					});

				//单元表
				tx.executeSql(
					"create table if not exists hf_yf_unit (id UNIQUE, user_id ,developer_name, batch_id, building_pro_id,building_id,building_name,name , downloaded ,download_time , is_updated )", [],
					function(tx, result) {
						console.log('创建验房任务表成功');
					},
					function(tx, error) {
						alert('创建验房任务表失败:' + error.message);
					});

				//房间表
				tx.executeSql(
					"create table if not exists hf_yf_house (id UNIQUE, batch_id , unit_id,name , is_updated , floor , state,house_type_id ,developer_name,building_pro_id,building_id,unit)", [],
					function(tx, result) {
						console.log('创建房间表成功');
					},
					function(tx, error) {
						alert('创建房间表失败:' + error.message);
					});

				//问题表
				tx.executeSql(
					"create table if not exists hf_yf_problem (id UNIQUE, batch_id , unit_id, house_id , data_state ,  state  ," +
					"urgent , part_id , part_name , desc ,desc_id, number ,check_item_name ,check_item_id , more_desc , img_before_fix , " +
					" img_after_fix , fix_desc , fix_expire , duty_id  , duty_name , contractor_id , contractor_name , " +
					" fix_live , create_time  , fix_time ,discard_reason )", [],
					function(tx, result) {
						console.log('创建问题表成功');
					},
					function(tx, error) {
						alert('创建问题表失败:' + error.message);
					});

				//复查记录表
				tx.executeSql(
					"create table if not exists hf_yf_recheck (id UNIQUE, batch_id ,unit_id, house_id , problem_id ,name , data_state , " +
					"passed , desc , images , time , user_id , username )", [],
					function(tx, result) {
						console.log('创建复查记录表成功');
					},
					function(tx, error) {
						alert('创建复查记录表失败:' + error.message);
					});

				//部位表
				tx.executeSql(
					"create table if not exists hf_yf_part (id UNIQUE, name )", [],
					function(tx, result) {
						console.log('创建部位表成功');
					},
					function(tx, error) {
						alert('创建部位表失败:' + error.message);
					});

				//检查项表
				//20170718 增加字段 type，装修类型。 1是精装；2是毛坯
				tx.executeSql(
					"create table if not exists hf_yf_check_item (id UNIQUE, name,contractor_id,description, type )", [],
					function(tx, result) {
						console.log('创建 检查项表 成功');
					},
					function(tx, error) {
						alert('创建 检查项表 失败:' + error.message);
					});

				//部位-检查项关系表
				tx.executeSql(
					"create table if not exists hf_yf_part_check_item_rel (id UNIQUE, part_id, item_id )", [],
					function(tx, result) {
						console.log('创建 部位-检查项关系表 成功');
					},
					function(tx, error) {
						alert('创建 部位-检查项关系表 失败:' + error.message);
					});

				//户型表
				tx.executeSql(
					"create table if not exists hf_yf_house_type (id UNIQUE, name )", [],
					function(tx, result) {
						console.log('创建 户型表 成功');
					},
					function(tx, error) {
						alert('创建 户型表 失败:' + error.message);
					});

				//户型-部位关系表
				//20170718 增加字段 renovation_type： 装修标准 1是精装;2是毛坯
				tx.executeSql(
					"create table if not exists hf_yf_house_type_part_rel (id UNIQUE, house_type_id,part_id,house_type_name,part_name,renovation_type )", [],
					function(tx, result) {
						console.log('创建 户型-部位关系表 成功');
					},
					function(tx, error) {
						alert('创建 户型-部位关系表 失败:' + error.message);
					});

				//检查项描述表
				tx.executeSql(
					"create table if not exists hf_yf_check_item_desc (id UNIQUE, name, item_id )", [],
					function(tx, result) {
						console.log('创建 检查项描述表 成功');
					},
					function(tx, error) {
						alert('创建 检查项描述表 失败:' + error.message);
					});

				//				//检查项-描述关系表
				//				tx.executeSql(
				//					"create table if not exists hf_yf_check_item_desc_rel (id UNIQUE, item_id,desc_id )", [],
				//					function(tx, result) {
				//						console.log('创建 检查项-描述关系表 成功');
				//					},
				//					function(tx, error) {
				//						alert('创建 检查项-描述关系表 失败:' + error.message);
				//					});

				//承建商/责任单位表
				tx.executeSql(
					"create table if not exists hf_yf_contractor (id UNIQUE, name )", [],
					function(tx, result) {
						console.log('创建 承建商/责任单位表 成功');
					},
					function(tx, error) {
						alert('创建 承建商/责任单位表 失败:' + error.message);
					});

				//问题图片表
				//status:  1:新建问题上传的; 2:复查未通过的; 3:整改通过的
				tx.executeSql(
					"create table if not exists hf_yf_problem_image (id UNIQUE, batch_id,unit_id,problem_id, status, recheck_id, url, data_state )", [],
					function(tx, result) {
						console.log('创建 问题图片表 成功');
					},
					function(tx, error) {
						alert('创建 问题图片表 失败:' + error.message);
					});

				//承建商-检查项-房间表
				tx.executeSql(
					"create table if not exists hf_yf_contractor_check_item_house_rel (id UNIQUE, contractor_id,check_item_id,house_id )", [],
					function(tx, result) {
						console.log('创建 承建商-检查项-房间表 成功');
					},
					function(tx, error) {
						alert('创建 承建商-检查项-房间表 失败:' + error.message);
					});
			});
		},
		/**
		 * 删除所有数据表
		 */
		deleteTables: function() {
			this.db.transaction(function(tx) {
				tx.executeSql('drop table hf_yf_user');
				tx.executeSql('drop table hf_yf_batch');
				tx.executeSql('drop table hf_yf_house');
				tx.executeSql('drop table hf_yf_problem');
				tx.executeSql('drop table hf_yf_recheck');

				tx.executeSql('drop table hf_yf_part');
				tx.executeSql('drop table hf_yf_check_item');
				tx.executeSql('drop table hf_yf_part_check_item_rel');
				tx.executeSql('drop table hf_yf_house_type');
				tx.executeSql('drop table hf_yf_house_type_part_rel');
				tx.executeSql('drop table hf_yf_check_item_desc');
				//				tx.executeSql('drop table hf_yf_check_item_desc_rel');
				tx.executeSql('drop table hf_yf_contractor');
				tx.executeSql('drop table hf_yf_problem_image');
				tx.executeSql('drop table hf_yf_contractor_check_item_house_rel');
				tx.executeSql('drop table hf_yf_unit');
			});
		},
		/**
		 * 清空数据表
		 */
		clearData: function() {
			this.db.transaction(function(tx) {
				tx.executeSql('delete  from   hf_yf_batch');
				tx.executeSql('delete  from   hf_yf_house');
				tx.executeSql('delete  from   hf_yf_problem');
				tx.executeSql('delete  from   hf_yf_recheck');

				tx.executeSql('delete  from   hf_yf_part');
				tx.executeSql('delete  from   hf_yf_check_item');
				tx.executeSql('delete  from   hf_yf_part_check_item_rel');
				tx.executeSql('delete  from   hf_yf_house_type');
				tx.executeSql('delete  from   hf_yf_house_type_part_rel');
				tx.executeSql('delete  from   hf_yf_check_item_desc');
				tx.executeSql('delete  from   hf_yf_contractor');
				tx.executeSql('delete  from   hf_yf_problem_image');
				tx.executeSql('delete  from   hf_yf_contractor_check_item_house_rel');
				tx.executeSql('delete  from   hf_yf_unit');
				tx.executeSql('UPDATE hf_yf_user set downloaded = 0');
			});
		},
		init: function() {
			var db_status_key = 'hf_yf_db_inited';
			if(!localStorage.getItem(db_status_key)) {
				localStorage.setItem(db_status_key, true);
				dao.createTabels();
				dao.insertDemoUser();
			}
		},
		clear: function() {
			localStorage.removeItem('hf_yf_db_inited');
			dao.deleteTables();
		},
		/**
		 * 插入测试用户
		 */
		insertDemoUser: function(values) {
			var _this = this;
			var sql = 'replace into hf_yf_user (id , name , downloaded) VALUES (1,"ghq",0)';
			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, null, function(tx, rs) {
						if(rs.rows.length > 0) {
							resolve(rs.rows.item(0).downloaded);
						}
						resolve(false);
					}, function(tx, error) {
						console.log('插入用户数据表出错 ' + error.message);
						reject('插入用户数据表出错');
					});
				});
			})
		},
		replaceTest: function() {
			var _this = this;
			var sql = 'replace INTO hf_yf_user (id , name , downloaded) VALUES (1,"ghq1",0)';
			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, null, function(tx, rs) {
						if(rs.rows.length > 0) {
							resolve(rs.rows.item(0).downloaded);
						}
						resolve(false);
					}, function(tx, error) {
						console.log('插入用户数据表出错 ' + error.message);
						reject('插入用户数据表出错');
					});
				});
			})
		},
		/**
		 * 插入用户
		 * @param {string} userId
		 */
		addUser: function(userId, username) {
			var _this = this;
			var sql = 'replace into hf_yf_user (id , name , downloaded) VALUES (?,?,0)';
			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [userId, username], function(tx, rs) {
						if(rs.rows.length > 0) {
							resolve(rs.rows.item(0).downloaded);
						}
						resolve(false);
					}, function(tx, error) {
						console.log('插入用户数据表出错 ' + error.message);
						reject('插入用户数据表出错');
					});
				});
			})
		},
		/**
		 * 
		 * 从数据库检查是否已经下载了用户的基础数据(任务列表)
		 * @param {string} userId
		 */
		checkUserData: function(userId) {
			var _this = this;
			var sql = 'SELECT * FROM hf_yf_user where id = ?';
			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [userId], function(tx, rs) {
						if(rs.rows.length > 0) {
							resolve(rs.rows.item(0));
						} else
							resolve(null);
					}, function(tx, error) {
						console.log('查询用户数据表出错');
						reject('查询用户数据表出错');
					});
				});
			})
		},
		/**
		 * 获取当前用户的批次列表
		 * @param {Object} userId
		 */
		getBatchList: function(userId) {
			var _this = this;
			var sql = 'SELECT hf_yf_batch.building_name, hf_yf_batch.name as batch_name,hf_yf_batch.name as batch_name,  hf_yf_batch.id as batch_id ,' +
				' hf_yf_unit.id as unit_id, hf_yf_unit.downloaded,hf_yf_unit.download_time,hf_yf_unit.is_updated,hf_yf_unit.id,hf_yf_unit.name, ' +
				' hf_yf_unit.building_name as unit_building_name, hf_yf_unit.building_id, hf_yf_unit.building_pro_id,hf_yf_unit.developer_name ' +
				' FROM hf_yf_batch,hf_yf_unit  where hf_yf_batch.user_id = ? and hf_yf_unit.batch_id = hf_yf_batch.id ';
			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [userId], function(tx, rs) {
						var batchs = {};
						for(var i = 0; i < rs.rows.length; i++) {
							var item = rs.rows.item(i);
							if(!batchs[item.batch_id]) {
								batchs[item.batch_id] = {
									building_name: item.building_name,
									name: item.batch_name,
									id: item.batch_id,
									units: []
								}
							}
							batchs[item.batch_id].units.push({
								id: item.id,
								name: item.name,
								downloaded: item.downloaded,
								download_time: item.download_time,
								is_updated: item.is_updated,
								building_name: item.unit_building_name,
								building_id: item.building_id,
								building_pro_id: item.building_pro_id,
								batch_id: item.batch_id,
								developer_name: item.developer_name
							})
						}
						//						console.dir(batchs);
						resolve(batchs);
					}, function(tx, error) {
						console.log('查询用户数据表出错 ' + error.message);
						reject('查询用户数据表出错');
					});
				});
			})
		},
		/**
		 * 获取当前用户的单元列表
		 * @param {Object} userId
		 */
		getUnitList: function(userId) {
			var _this = this;
			var sql = 'SELECT * FROM hf_yf_unit where user_id = ?';
			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [userId], function(tx, rs) {
						var result = [];
						for(var i = 0; i < rs.rows.length; i++) {
							result.push(rs.rows.item(i));
						}
						resolve(result);
					}, function(tx, error) {
						console.log('查询用户数据表出错 ' + error.message);
						reject('查询用户数据表出错');
					});
				});
			})
		},
		/**
		 * 从服务器下载任务列表后, 添加到数据库
		 * @param {Object} obj
		 */
		addBatch: function(objs) {
			var _this = this;
			var sql = 'replace into hf_yf_batch (id,user_id , name , downloaded ,download_time , is_updated,building_name ) values (?,?,?,?,?,?,?)';

			var valFn = function(obj) {
				return [obj.id, obj.userId, obj.name, obj.isDownload, obj.downloadTime, obj.isUpdated, obj.buildingName]
			}
			return this.insertCom(sql, valFn, objs, '添加任务 出错');
		},
		/**
		 * 更新用户是否下载的标志
		 * @param {Object} userId
		 * @param {Object} isDownload
		 */
		updateUserDownload: function(userId, isDownload) {
			var _this = this;
			var sql = 'UPDATE hf_yf_user set downloaded = ? where id = ?';
			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [isDownload, userId], function(tx, rs) {
						if(rs.rows.length > 0) {
							resolve(rs.rows.item(0).downloaded);
						}
						resolve(true);
						console.log('更新用户下载 成功 ')
					}, function(tx, error) {
						console.log('更新用户是否下载的标志 出错');
						reject('更新用户是否下载的标志 出错');
					});
				});
			})
		},
		/**
		 * 向数据库中添加房屋信息
		 * @param {Array} objs
		 */
		addHouse: function(objs) {
			var sql = 'replace into hf_yf_house (id , batch_id , unit_id,name , is_updated , floor , state, house_type_id,developer_name,building_pro_id,building_id,unit ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)';
			var valFn = function(obj) {　　
				return [obj.id, obj.batchId, obj.unitId, obj.name, obj.isUpdated, obj.floor, obj.state, obj.houseTypeId, obj.developerName, obj.buildingProId, obj.buildingId, obj.unit];
			}
			return this.insertCom(sql, valFn, objs, '插入房屋数据库出错');
		},
		/**
		 * 公共插入方法
		 * @param {String} sql sql语句
		 * @param {function} valFn 返回与sql语句相对的数组值
		 * @param {Object||Array} objs 数据.数组或者对象
		 * @param {String} errMsg 错误消息
		 * 2017-07-05
		 */
		insertCom: function(sql, valFn, objs, errMsg) {
			var _this = this;
			var count = 0,
				length = _.isArray(objs) ? objs.length : 1;

			if(length == 0)
				return Promise.resolve();

			var insert = function(tx, obj, resolve, reject) {
				tx.executeSql(sql, valFn(obj), function(tx, rs) {
					count++;
					if(count == length)
						resolve(true);
				}, function(tx, error) {
					console.log(errMsg + ' id= ' + obj.id + ' ' + error.message);
					reject(errMsg);
				});
			}

			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					if(_.isArray(objs)) {
						objs.forEach(function(p) {
							insert(tx, p, resolve, reject)
						})
					} else
						insert(tx, objs, resolve, reject);
				});
			})
		},
		/**
		 * 删除数据
		 * @param {string} table 表明
		 * @param {array} ids id数组
		 */
		deleteCom: function(table, ids) {
			if(!_.isArray(ids))
				ids = [ids];
			var _this = this;
			var sql = 'delete from ' + table + ' where id in ';
			sql += ' ("' + ids.join('","') + '") ';

			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, null, function(tx, rs) {
						resolve(true);
					}, function(tx, error) {
						console.log('删除数据表 出错 ' + sql + error.message);
					});
				});
			})
		},
		deleteParts: function(ids) {
			return this.deleteCom('hf_yf_part', ids);
		},
		deleteCheckItem: function(ids) {
			return this.deleteCom('hf_yf_check_item', ids);
		},
		deleteItemDesc: function(ids) {
			return this.deleteCom('hf_yf_check_item_desc', ids);
		},
		deleteContractor: function(ids) {
			return this.deleteCom('hf_yf_contractor', ids);
		},
		deletePartCheckItemRelation: function(ids) {
			return this.deleteCom('hf_yf_part_check_item_rel', ids);
		},
		deleteHouse: function(ids) {
			return this.deleteCom('hf_yf_house', ids);
		},
		deleteContractorCheckItemHouseRel: function(ids) {
			return this.deleteCom('hf_yf_contractor_check_item_house_rel', ids);
		},
		deleteHouseTypePartRelation: function(ids) {
			return this.deleteCom('hf_yf_house_type_part_rel', ids);
		},
		deleteProblem: function(ids) {
			return this.deleteCom('hf_yf_problem', ids);
		},
		deleteBatchesByUser: function(userId) {
			var _this = this;
			var batchSql = 'delete from hf_yf_batch where user_id = ?';
			var unitSql = 'delete from hf_yf_unit where user_id = ?';
			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(batchSql, [userId]);
					tx.executeSql(unitSql, [userId]);
				});
			})
		},
		/**
		 * 添加问题
		 * @param {Array} obj
		 */
		addProblem: function(objs) {
			var _this = this;
			var sql = 'replace into hf_yf_problem (id , batch_id , unit_id,house_id , data_state  , state  ,' +
				'urgent , part_id , part_name , desc ,desc_id, number ,check_item_name ,check_item_id , more_desc , img_before_fix , ' +
				' img_after_fix , fix_desc , fix_expire , duty_id  , duty_name , contractor_id , contractor_name , ' +
				' fix_live , create_time  , fix_time,discard_reason ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';

			var valFn = function(obj) {
				return [obj.id, obj.batchId, obj.unitId, obj.houseId, obj.dataState, obj.state, obj.urgent, obj.partId,
					obj.partName, obj.desc, obj.descId, obj.number, obj.checkItemName, obj.checkItemId,
					obj.moreDesc, obj.imgBeforeFix, obj.imgAfterFix, obj.fixDesc, obj.fixExpire, obj.dutyId, obj.dutyName,
					obj.contractorId, obj.contractorName, obj.fixLive, obj.createTime, obj.fixTime, obj.discardReason ? obj.discardReason : ''
				]
			};

			return this.insertCom(sql, valFn, objs, '插入问题数据库出错');
		},
		/**
		 * 清除问题数据表
		 */
		clearProblem: function() {
			var _this = this;
			var sql = 'DELETE  FROM hf_yf_problem';
			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, null, function(tx, rs) {
						console.log('清除问题数据表 成功')
						resolve(true);
					}, function(tx, error) {
						console.log('清除问题数据表 出错 ' + error.message);
						reject('清除问题数据表 出错');
					});
				});
			})
		},
		/**
		 * 添加复查
		 * @param {Array} obj
		 */
		addRecheck: function(objs) {
			var sql = 'replace into hf_yf_recheck (id , batch_id ,unit_id, house_id , problem_id , data_state , ' +
				'passed , desc , images , time , user_id , username ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)';

			var valFn = function(obj) {　　
				return [obj.id, obj.batchId, obj.unitId, obj.houseId, obj.problemId, obj.dataState, obj.passed,
					obj.desc, obj.images, obj.time, obj.userId, obj.username
				]
			};

			return this.insertCom(sql, valFn, objs, '插入复查出错');
		},
		/**
		 * 更新单元信息
		 * @param {Object} values
		 */
		updateUnitDownLoad: function(values) {
			if(!values.id)
				return Promise.reject('需传入单元Id');

			var _this = this;
			var sql = 'UPDATE hf_yf_unit set downloaded = ?,download_time=? where id = ?';
			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [values.downloaded, Date.now(), values.id], function(tx, rs) {
						var effectRow = rs.rowsAffected;
						if(effectRow > 0) {
							resolve(values.downloaded);
						} else {
							reject('未找到单元');
						}
						console.log('更新任务信息 成功 ')
					}, function(tx, error) {
						console.log('更新任务信息 出错');
						reject('更新任务信息 出错');
					});
				});
			})
		},
		/**
		 * 获取房间列表
		 * @param {Object} batchId
		 */
		getHouseList: function(batchId, unitId) {
			if(!batchId || !unitId)
				return Promise.reject('需传入任务Id');

			var _this = this;
			var sql = 'select * from hf_yf_house where batch_id = ? and unit_id = ?';
			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [batchId, unitId], function(tx, rs) {
						var result = [];
						for(var i = 0; i < rs.rows.length; i++) {
							result.push(rs.rows.item(i));
						}
						resolve(result);
						console.log('获取房间列表 成功 ')
					}, function(tx, error) {
						console.log('获取房间列表 出错');
						reject('获取房间列表 出错');
					});
				});
			})
		},
		/**
		 * 根据单元获取房间列表
		 * @param {String} batchId
		 * @param {String} buildingProId
		 * @param {String} buildingId
		 * @param {String} unit
		 */
		getHouseListByUnit: function(batchId, buildingProId, buildingId, unit) {
			if(!batchId || !unit || !buildingProId || !buildingId)
				return Promise.reject('参数错误');

			var _this = this;
			var sql = 'select * from hf_yf_house where batch_id = ? and building_pro_id = ? and building_id = ? and unit = ?';

			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [batchId, buildingProId, buildingId, unit], function(tx, rs) {
						var result = [];
						for(var i = 0; i < rs.rows.length; i++) {
							result.push(rs.rows.item(i));
						}

						resolve(result);
						console.log('获取房间列表 成功 ')
					}, function(tx, error) {
						console.log('获取房间列表 出错');
						reject('获取房间列表 出错');
					});
				});
			})
		},
		/**
		 * 获取房间的问题列表
		 * @param {Object} houseId
		 */
		getProblemsByHouse: function(houseId) {
			if(!houseId)
				return Promise.reject('需传入房间Id');

			console.log(houseId)
			var _this = this;
			var sql = 'select p.id,p.state,p.desc_id,p.urgent,p.desc,t.name as part_name from hf_yf_problem as p,hf_yf_part as t where p.house_id = ? and p.state != 5 and p.part_id = t.id';
			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [houseId], function(tx, rs) {
						var result = [];
						for(var i = 0; i < rs.rows.length; i++) {
							result.push(rs.rows.item(i));
						}
						console.dir(result);
						resolve(result);
						console.log('获取房间问题列表 成功 ')
					}, function(tx, error) {
						console.log('获取房间问题列表 出错');
						reject('获取房间问题列表 出错');
					});
				});
			})
		},
		/**
		 * 获取问题详细信息
		 * @param {Object} id
		 */
		getProblem: function(id) {
			if(!id)
				return Promise.reject('需传入问题Id');

			var _this = this;
			var sql = 'select p.id,p.number,p.more_desc,p.fix_live,p.duty_name,p.desc_id,t.name as part_name ,i.name as check_item_name,' +
				' p.create_time,c.name as contractor_name, p.desc,p.state ' +
				' from hf_yf_problem as p,hf_yf_part as t, hf_yf_check_item as i,hf_yf_contractor as c ' +
				' where p.id = ?  and p.part_id = t.id and p.check_item_id = i.id and p.contractor_id = c.id';
			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [id], function(tx, rs) {
						console.dir(rs.rows.length);
						if(rs.rows.length > 0) {
							var problem = {};
							for(var k in rs.rows.item(0)) { //ios下,改变数据库查出来的字段,赋值不成功. 20170630
								if(k != 'img_before_fix' && k != 'img_after_fix')
									problem[k] = rs.rows.item(0)[k];
							}
							//查询图片信息
							sql = 'select * from hf_yf_problem_image where problem_id = ?';
							_this.db.transaction(function(tx) {　　
								tx.executeSql(sql, [id], function(tx, rs) {
									console.log('问题图片: ' + rs.rows.length);
									var before = [],
										after = [];
									for(var i = 0; i < rs.rows.length; i++) {
										var item = rs.rows.item(i);
										if(item.recheck_id == '')
											before.push(item)
									}
									console.log(JSON.stringify(before))
									problem.img_before_fix = before;
									problem.img_after_fix = after;
									resolve(problem);
								}, function(e) {})
							});
						} else {
							resolve({});
						}
						//resolve(rs.rows.length > 0 ? rs.rows.item(0) : {});
						console.log('获取问题详细信息 成功 ')
					}, function(tx, error) {
						console.log('获取问题详细信息 出错' + error.message);
						reject('获取房间列表获取问题详细信息出错');
					});
				});
			})
		},
		/**
		 * 获取问题的描述(多个)
		 * @param {string} ids
		 */
		getProblemDescByIds: function(ids) {
			var _this = this;
			ids = '"' + ids.split(',').join('","') + '"';

			console.log(ids)
			var sql = 'SELECT * from hf_yf_check_item_desc where id in ( ' + ids + ' ) ';
			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [], function(tx, rs) {
						var result = '';
						for(var i = 0; i < rs.rows.length; i++) {
							if(i > 0)
								result += ';';
							result += rs.rows.item(i).name;
						}
						resolve(result);
						//						console.log(result);
					}, function(tx, error) {
						console.log('根据检查项 获取检查项描述 出错 ' + error.message);
						reject('根据检查项 获取检查项描述 出错');
					});
				});
			})
		},
		/**
		 * 获取复查列表
		 * @param {Object} problemId
		 */
		getRechecks: function(problemId) {
			if(!problemId)
				return Promise.reject('需传入问题Id');

			var _this = this;
			var sql = 'select * from hf_yf_recheck where problem_id = ? order by time desc';
			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [problemId], function(tx, rs) {
						var rechecks = [];
						for(var i = 0; i < rs.rows.length; i++) {
							rechecks.push(rs.rows.item(i));
						}

						sql = 'select * from hf_yf_problem_image where problem_id = ? and recheck_id <> ""';
						_this.db.transaction(function(tx) {　　
							tx.executeSql(sql, [problemId], function(tx, rs) {
								var images = [];
								for(var i = 0; i < rs.rows.length; i++) {
									images.push(rs.rows.item(i));
								}
								resolve({
									recheckList: rechecks,
									imageList: images
								});
								console.log('获取复查列表图片 成功 ' + images.length)
							});
						})
						console.log('获取复查列表 成功 ')
					}, function(tx, error) {
						console.log('获取复查列表 出错');
						reject('获取复查列表 出错');
					});
				});
			})
		},
		/**
		 * 添加房屋户型
		 * @param {Object} objs
		 */
		addHouseType: function(objs) {
			var sql = 'replace into hf_yf_house_type (id , name ) VALUES (?,?)';
			var valFn = function(obj) {　　
				return [obj.id, obj.name]
			}

			return this.insertCom(sql, valFn, objs, '添加房屋户型 出错');
		},
		/**
		 * 添加检查部位
		 * @param {Object} obj
		 */
		addPart: function(objs) {
			var sql = 'replace into hf_yf_part (id , name ) VALUES (?,?)';

			var valFn = function(obj) {　　
				return [obj.id, obj.name]
			}

			return this.insertCom(sql, valFn, objs, '添加检查部位 出错');
		},
		/**
		 * 添加房屋户型-部位关系
		 * @param {Object} obj
		 */
		addHouseTypePartRelation: function(objs) {
			var sql = 'replace into hf_yf_house_type_part_rel (id , house_type_id, part_id,house_type_name,part_name,renovation_type ) VALUES (?,?,?,?,?,?)';

			var valFn = function(obj) {　　
				return [obj.id, obj.houseTypeId, obj.partId, obj.houseTypeName, obj.partName, obj.renovationType];
			}

			return this.insertCom(sql, valFn, objs, '添加房屋户型-部位关系 出错');
		},
		/**
		 * 添加检查项目
		 * @param {Object} obj
		 */
		addCheckItem: function(objs) {
			var _this = this;
			var sql = 'replace into hf_yf_check_item (id , name,description,type ) VALUES (?,?,?,?)';

			var valFn = function(obj) {　　
				return [obj.id, obj.name, obj.description, obj.type]
			}

			return this.insertCom(sql, valFn, objs, '添加检查项目 出错');
		},
		/**
		 * 添加部位-检查项目关系
		 * @param {Object} obj
		 */
		addPartCheckItemRelation: function(objs) {
			var sql = 'replace into hf_yf_part_check_item_rel (id , part_id,item_id ) VALUES (?,?,?)';

			var valFn = function(obj) {　　
				return [obj.id, obj.partId, obj.itemId];
			}

			return this.insertCom(sql, valFn, objs, '添加部位-检查项目关系 出错');
		},
		/**
		 * 添加检查项目描述
		 * @param {Object} obj
		 */
		addCheckItemDesc: function(objs) {
			var sql = 'replace into hf_yf_check_item_desc (id , name ,item_id) VALUES (?,?,?)';

			var valFn = function(obj) {　　
				return [obj.id, obj.name, obj.item_id];
			}

			return this.insertCom(sql, valFn, objs, '添加检查项目描述 出错');
		},
		/**
		 * 添加检查项目-描述关系
		 * @param {Object} obj
		 */
		addCheckItemDescRelation: function(objs) {
			var sql = 'replace into hf_yf_check_item_desc_rel (id , item_id,desc_id ) VALUES (?,?,?)';

			var valFn = function(obj) {　　
				return [obj.id, obj.itemId, obj.descId];
			}

			return this.insertCom(sql, valFn, objs, '添加检查项目-描述关系 出错');
		},
		/**
		 * 添加承建商/责任单位
		 * @param {Object} obj
		 */
		addContractor: function(objs) {
			var sql = 'replace into hf_yf_contractor (id , name ) VALUES (?,?)';

			var valFn = function(obj) {　　
				return [obj.id, obj.name];
			}

			return this.insertCom(sql, valFn, objs, '添加承建商/责任单位 出错');
		},
		/**
		 * 根据房屋 获取 部位信息
		 * @param {string} houseId
		 */
		getPartListByHouse: function(houseId) {
			var _this = this;
			var sql = 'SELECT hf_yf_part.id,hf_yf_part.name from hf_yf_part,hf_yf_house,hf_yf_house_type_part_rel where hf_yf_house.id = ? and hf_yf_house.house_type_id = hf_yf_house_type_part_rel.house_type_id and hf_yf_house_type_part_rel.part_id = hf_yf_part.id';
			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [houseId], function(tx, rs) {
						var result = [];
						for(var i = 0; i < rs.rows.length; i++) {
							result.push(rs.rows.item(i));
						}
						resolve(result);
						console.dir(result);
					}, function(tx, error) {
						console.log('根据房屋 获取 部位信息 出错 ' + error.message);
						reject('根据房屋 获取 部位信息 出错');
					});
				});
			})
		},
		/**
		 * 根据房屋 获取 部位信息,直接从关系表获取,
		 * @param {string} houseId
		 */
		getPartListByHouseNew: function(houseId) {
			var _this = this;
			var sql = 'SELECT rel.part_id as id,rel.part_name as name,rel.renovation_type ' +
				' from hf_yf_house as house,hf_yf_house_type_part_rel as rel' +
				' where house.id = ? and house.house_type_id = rel.house_type_id';
			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [houseId], function(tx, rs) {
						var result = [];
						for(var i = 0; i < rs.rows.length; i++) {
							result.push(rs.rows.item(i));
						}
						resolve(result);
					}, function(tx, error) {
						console.log('根据房屋 获取 部位信息 出错 ' + error.message);
						reject('根据房屋 获取 部位信息 出错');
					});
				});
			})
		},
		/**
		 * 根据检查部位 获取检查项
		 * @param {Object} partId
		 */
		getCheckItemByPart: function(partId, renovationType) {
			var _this = this;
			var sql = 'SELECT item.id,item.name,item.description ' +
				' from hf_yf_check_item as item,hf_yf_part_check_item_rel as rel ' +
				' where rel.part_id = ? and  item.id = rel.item_id and item.type = ?';
			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [partId, renovationType], function(tx, rs) {
						var result = [];
						for(var i = 0; i < rs.rows.length; i++) {
							result.push(rs.rows.item(i));
						}
						resolve(result);
						console.dir(result);
					}, function(tx, error) {
						console.log('根据检查部位 获取检查项 出错 ' + error.message);
						reject('根据检查部位 获取检查项 出错');
					});
				});
			})
		},
		/**
		 * 根据检查项 获取检查项描述
		 * @param {Object} itemId
		 */
		getCheckDescByItem: function(itemId) {
			var _this = this;
			var sql = 'SELECT * from hf_yf_check_item_desc where hf_yf_check_item_desc.item_id = ? ';
			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [itemId], function(tx, rs) {
						var result = [];
						for(var i = 0; i < rs.rows.length; i++) {
							result.push(rs.rows.item(i));
						}
						resolve(result);
						//console.dir(result);
					}, function(tx, error) {
						console.log('根据检查项 获取检查项描述 出错 ' + error.message);
						reject('根据检查项 获取检查项描述 出错');
					});
				});
			})
		},
		/**
		 * 获取承建商/责任人列表
		 */
		getContractorList: function() {
			var _this = this;
			var sql = 'SELECT * from hf_yf_contractor';
			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [], function(tx, rs) {
						var result = [];
						for(var i = 0; i < rs.rows.length; i++) {
							result.push(rs.rows.item(i));
						}
						resolve(result);
						console.dir(result);
					}, function(tx, error) {
						console.log('获取承建商/责任人列表 出错 ' + error.message);
						reject('获取承建商/责任人列表 出错');
					});
				});
			})
		},
		/**
		 * 更新房屋信息
		 * @param {Object} obj
		 */
		updateHouse: function(obj) {
			if(!obj.id)
				return;

			var _this = this;
			var sql = 'update hf_yf_house set is_updated = 1 ',
				values = [],
				count = 0;
			_.each(obj, function(val, key) {
				if(key != 'id') {
					sql += ' , ';
					sql += key + ' = ? ';
					count++;
					values.push(val);
				}
			})

			sql += ' where id = ?';
			values.push(obj.id);

			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, values, function(tx, rs) {
						resolve();
					}, function(tx, error) {
						console.log('更新房屋信息 出错 ' + error.message);
						reject('更新房屋信息 出错');
					});
				});
			})
		},
		/**
		 * 更新批次任务信息
		 * @param {Object} obj
		 */
		updateBatch: function(obj) {
			if(!obj.id)
				return Promise.reject('未传入批次Id');

			var _this = this;
			var sql = 'update hf_yf_batch set is_updated = 1 ',
				values = [],
				count = 0;
			_.each(obj, function(val, key) {
				if(key != 'id') {
					sql += ' , ';
					sql += key + ' = ? ';
					count++;
					values.push(val);
				}
			})
			sql += ' where id = ?';
			values.push(obj.id);

			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, values, function(tx, rs) {
						resolve();
					}, function(tx, error) {
						console.log('更新批次任务信息 出错 ' + error.message);
						reject('更新批次任务信息 出错');
					});
				});
			})
		},
		/**
		 * 添加问题图片
		 * @param {Object} obj
		 */
		addProblemImage: function(objs) {
			var sql = 'replace into hf_yf_problem_image (id , batch_id,unit_id,problem_id, status,recheck_id, url, data_state) VALUES (?,?,?,?,?,?,?,?)';
			var valFn = function(obj) {　　
				return [obj.id, obj.batchId, obj.unitId, obj.problemId, obj.status, obj.recheckId ? obj.recheckId : '', obj.url, obj.dataState];
			}

			return this.insertCom(sql, valFn, objs, '添加问题图片 出错');
		},
		/**
		 * 更新问题图片
		 * @param {Object} obj
		 */
		updateProblemImage: function(obj) {
			if(!obj.id)
				return;

			var _this = this;

			var _this = this;
			var sql = 'update hf_yf_problem_image set ',
				values = [],
				count = 0;
			_.each(obj, function(val, key) {
				if(key != 'id') {
					if(count != 0)
						sql += ' , ';
					sql += key + ' = ? ';
					count++;
					values.push(val);
				}
			})
			sql += ' where id = ?';
			values.push(obj.id);

			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, values, function(tx, rs) {
						resolve();
					}, function(tx, error) {
						console.log('更新问题图片状态 出错 ' + error.message);
						reject('更新问题图片状态 出错');
					});
				});
			})
		},
		/**
		 * 更新问题状态
		 * @param {Object} values
		 */
		updateProblem: function(obj) {
			if(!obj.id)
				return;

			var _this = this;

			var _this = this;
			var sql = 'update hf_yf_problem set ',
				values = [],
				count = 0;
			_.each(obj, function(val, key) {
				if(key != 'id') {
					if(count != 0)
						sql += ' , ';
					sql += key + ' = ? ';
					count++;
					values.push(val);
				}
			})
			sql += ' where id = ?';
			values.push(obj.id);

			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, values, function(tx, rs) {
						resolve();
					}, function(tx, error) {
						console.log('更新问题状态 出错 ' + error.message);
						reject('更新问题状态 出错');
					});
				});
			})
		},
		/**
		 * 获取房间的各种问题的数量
		 * @param {Object} id
		 */
		getProblemsStateCountByHouse: function(id) {
			var _this = this;

			var sql = 'SELECT state, count(*) as count from hf_yf_problem where house_id = ? group by state';
			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [id], function(tx, rs) {
						var result = {};
						var item;
						for(var i = 0; i < rs.rows.length; i++) {
							item = rs.rows.item(i);
							result[item.state] = item.count;
						}
						resolve(result);
//						console.log(JSON.stringify(result));
					}, function(tx, error) {
						console.log('获取房间的各种问题的数量 出错 ' + error.message);
						reject('获取房间的各种问题的数量 出错');
					});
				});
			})
		},
		/**
		 * 获取本地更新了的房间数据
		 * @param {Object} batchId
		 */
		getLocalUpdatedHouses: function(unitIds) {
			var _this = this;

			var sql = 'SELECT * from hf_yf_house where is_updated = 1';
			if(unitIds)
				sql += ' and unit_id in ("' + unitIds.join('","') + '")';

			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [], function(tx, rs) {
						var result = [];
						for(var i = 0; i < rs.rows.length; i++) {
							result.push(rs.rows.item(i));
						}
						resolve(result);
						//						console.log(JSON.stringify(result));
					}, function(tx, error) {
						console.log('获取本地更新了的房间数据 出错 ' + error.message);
						reject('获取本地更新了的房间数据 出错');
					});
				});
			})
		},
		/**
		 * 获取本地更新了的问题数据
		 * @param {Object} batchId
		 */
		getLocalNewAndUpdatedProblems: function(unitIds) {
			var _this = this;

			var sql = 'SELECT * from hf_yf_problem where data_state in (1, 2)';
			if(unitIds)
				sql += ' and unit_id in ("' + unitIds.join('","') + '")';

			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [], function(tx, rs) {
						var result = [];
						for(var i = 0; i < rs.rows.length; i++) {
							result.push(rs.rows.item(i));
						}
						resolve(result);
					}, function(tx, error) {
						console.log('获取本地更新了的问题数据 出错 ' + error.message);
						reject('获取本地更新了的问题数据 出错');
					});
				});
			})
		},
		/**
		 * 获取本地更新了的复查数据
		 * @param {Object} batchId
		 */
		getLocalNewRechecks: function(unitIds) {
			var _this = this;

			var sql = 'SELECT * from hf_yf_recheck where data_state in (1, 2)';
			if(unitIds)
				sql += ' and unit_id in ("' + unitIds.join('","') + '")';

			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [], function(tx, rs) {
						var result = [];
						for(var i = 0; i < rs.rows.length; i++) {
							result.push(rs.rows.item(i));
						}
						resolve(result);
						//						console.log(JSON.stringify(result));
					}, function(tx, error) {
						console.log('获取本地更新了的复查数据 出错 ' + error.message);
						reject('获取本地更新了的复查数据 出错');
					});
				});
			})
		},
		/**
		 * 获取本地更新了的图片数据
		 * @param {Object} batchId
		 */
		getLocalNewImages: function(unitIds) {
			var _this = this;

			var sql = 'SELECT * from hf_yf_problem_image where data_state in (1, 2) ';
			if(unitIds)
				sql += ' and unit_id in ("' + unitIds.join('","') + '")';

			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [], function(tx, rs) {
						var result = [];
						for(var i = 0; i < rs.rows.length; i++) {
							result.push(rs.rows.item(i));
						}
						resolve(result);
						//						console.log(JSON.stringify(result));
					}, function(tx, error) {
						console.log('获取本地更新了的图片数据 出错 ' + error.message);
						reject('获取本地更新了的图片数据 出错');
					});
				});
			})
		},
		/**
		 * 根据检查部位 和搜索的字符串 获取检查项
		 * @param {Object} partId
		 * @param {Object} search
		 */
		getCheckItemByPartAndSearch: function(partId, search) {
			var _this = this;
			var sql = 'SELECT hf_yf_check_item.id,hf_yf_check_item.name from hf_yf_check_item,hf_yf_part_check_item_rel where hf_yf_part_check_item_rel.part_id = ? and  hf_yf_check_item.id = hf_yf_part_check_item_rel.item_id and hf_yf_check_item.name like ?';
			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [partId, '%' + search + '%'], function(tx, rs) {
						var result = [];
						for(var i = 0; i < rs.rows.length; i++) {
							result.push(rs.rows.item(i));
						}
						resolve(result);
					}, function(tx, error) {
						console.log('根据检查部位 获取检查项 出错 ' + error.message);
						reject('根据检查部位 获取检查项 出错');
					});
				});
			})
		},
		/**
		 * 插入承建商-检查项-房间关系表
		 * @param {Object} obj
		 */
		addContractorCheckItemHouseRel: function(objs) {
			var sql = 'replace into hf_yf_contractor_check_item_house_rel (id , contractor_id,check_item_id,house_id) VALUES (?,?,?,?)';

			var valFn = function(obj) {　　
				return [obj.id, obj.contractorId, obj.checkItemId, obj.houseId];
			}

			return this.insertCom(sql, valFn, objs, '添加承建商-检查项-房间关系表 出错');
		},
		/**
		 * 获取承建商
		 * @param {Object} itemId
		 * @param {Object} houseId
		 */
		getContractorByCheckItem: function(itemId, houseId) {
			var _this = this;
			console.log(itemId + ' ' + houseId)
			var sql = 'SELECT con.id,con.name from hf_yf_contractor_check_item_house_rel as rel,hf_yf_contractor as con where rel.check_item_id = ? and rel.house_id = ? and con.id = rel.contractor_id';
			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, [itemId, houseId], function(tx, rs) {
						var result = rs.rows.length > 0 ? rs.rows.item(0) : {};
						//						console.log(JSON.stringify(result))
						resolve(result);
					}, function(tx, error) {
						console.log('根据检查部位 获取检查项 出错 ' + error.message);
						reject('根据检查部位 获取检查项 出错');
					});
				});
			})
		},
		/**
		 * 插入单元表
		 * @param {Object} obj
		 */
		addUnit: function(objs) {
			var sql = 'replace into hf_yf_unit (id , user_id , batch_id, name , downloaded ,download_time , is_updated,building_pro_id,building_id,building_name,developer_name) VALUES (?,?,?,?,?,?,?,?,?,?,?)';

			var valFn = function(obj) {　　
				return [obj.id, obj.userId, obj.batchId, obj.name, obj.downloaded, obj.downloadTime, obj.isUpdated, obj.buildingProId, obj.buildingId, obj.buildingName, obj.developerName];
			}

			return this.insertCom(sql, valFn, objs, '单元表 出错');
		},
		/**
		 * 更新单元状态
		 * @param {Object} values
		 */
		updateUnit: function(obj) {
			if(!obj.id)
				return;

			var _this = this;

			var _this = this;
			var sql = 'update hf_yf_unit set ',
				values = [],
				count = 0;
			_.each(obj, function(val, key) {
				if(key != 'id') {
					if(count != 0)
						sql += ' , ';
					sql += key + ' = ? ';
					count++;
					values.push(val);
				}
			})
			sql += ' where id = ?';
			values.push(obj.id);

			return new Promise(function(resolve, reject) {
				_this.db.transaction(function(tx) {　　
					tx.executeSql(sql, values, function(tx, rs) {
						resolve();
					}, function(tx, error) {
						console.log('更新问题状态 出错 ' + error.message);
						reject('更新问题状态 出错');
					});
				});
			})
		},
		/**
		 * 设置数据的状态为normal 
		 * 上传后调用
		 * @param {string} unitId
		 */
		setDataStateToNormalByUnit: function(unitId) {
			var problemSql = 'update hf_yf_problem set data_state = 0 where unit_id = ?',
				recheckSql = 'update hf_yf_recheck set data_state = 0 where unit_id = ?',
				imageSql = 'update hf_yf_problem_image set data_state = 0 where unit_id = ?',
				unitSql = 'update hf_yf_unit set is_updated = 0 where id = ?',
				houseSql = 'update hf_yf_house set is_updated = 0 where unit_id = ? and is_updated = 1'
			count = 0,
				_this = this;

			return new Promise(function(resolve, reject) {
				var e = function(tx, error) {
					console.log('上传后调用  设置数据的状态为normal 出错' + error.message);
				};
				var suc = function(tx, rs) {
					count++;
					if(count == 5)
						resolve();
				};

				_this.db.transaction(function(tx) {　　
					tx.executeSql(problemSql, [unitId], suc, e);
					tx.executeSql(recheckSql, [unitId], suc, e);
					tx.executeSql(imageSql, [unitId], suc, e);
					tx.executeSql(unitSql, [unitId], suc, e);
					tx.executeSql(houseSql, [unitId], suc, e);
				});
			})
		}
	};

	dao.openDB();
	w.dao = dao;
})(window);